import type { MultipleConditionSearchSchema } from '@/components/multiple-condition-search'
import { getCodesOptions } from '@/utils/country'

export default function useConfig() {
  const tableColumns = computed(() =>
    buildColumns([
      {
        title: '区域名称',
        dataIndex: 'name',
        width: 120,
        render({ record }) {
          const name = JSON.parse(record.name)
          return name['zh-CN']
        },
      },
      {
        title: '区域英文名',
        dataIndex: 'name_en',
        width: 120,
        render({ record }) {
          const name = JSON.parse(record.name)
          return name.en
        },
      },
      {
        title: '所属国家',
        dataIndex: 'name1',
        width: 120,
        render({ record }) {
          return getOptionLabel(
            record?.country?.toLowerCase(),
            getCodesOptions(),
          )
        },
      },
      {
        title: '区域地址',
        dataIndex: 'region_url',
        maxWidth: 150,
        format: 'copy',
      },
      {
        title: 'Region',
        dataIndex: 'region',
        maxWidth: 100,
      },
      {
        title: '备注',
        dataIndex: 'remark',
        maxWidth: 155,
        slotName: 'remark',
      },
      {
        title: '状态',
        width: 100,
        slotName: 'status',
      },
      {
        title: '创建时间',
        dataIndex: 'created_at',
        format: 'date-time',
        width: 160,
      },

      {
        title: '操作',
        fixed: 'right',
        slotName: 'actions',
        width: 70,
        cellClass: 'actions-cell',
      },
    ]),
  )

  const filterSchemes = ref<MultipleConditionSearchSchema>({
    widgets: [
      {
        type: 'input',
        field: 'name',
        label: '区域名称',
        placeholder: '请输入区域名称',
      },
      {
        type: 'input',
        field: 'region_url',
        label: '区域地址',
        placeholder: '请输入区域地址',
      },
      {
        type: 'input',
        field: 'region',
        label: 'Region',
        placeholder: '请输入Region',
      },
    ],
  })

  return {
    tableColumns,
    filterSchemes,
  }
}
